﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

// std headers
#include <cstdint>
#include <string>
#include <memory>

// qt headers

// gcmp headers

// custom headers
#include "GcsService.h"


class QString;
class QSqlDatabase;

namespace gmepgcs
{
    struct IProjectComponent;
}

namespace gmepgcs
{
    class GCS_SERVICE_EXPORTS GmepLocalDbService
    {
    private:
        explicit GmepLocalDbService();
        GmepLocalDbService(const GmepLocalDbService &) = default;
        GmepLocalDbService &operator=(const GmepLocalDbService &) = default;
        virtual ~GmepLocalDbService();

    public:
        static GmepLocalDbService *Get();
        std::shared_ptr<IProjectComponent> GetComponentOfMaxVersion(const std::wstring &projectId, const std::wstring &componentId) const;
        std::map<std::wstring, int> GetComponentsMaxVersion(const std::wstring & projectId, const std::wstring & strIdRange);

        bool IsComponentSyncable(const std::wstring &projectId, const std::wstring &componentId, const int32_t &versionInCloud, const bool &isDeletedInCloud = false) const;
        bool SyncComponent(const std::wstring &projectId, const std::wstring &componentId, const int32_t &versionInCloud, std::wstring &errorMessage) const;

    private:
        void Init();
        QSqlDatabase GetLocalDb(const std::wstring &projectId) const;

    private:
        static GmepLocalDbService *s_pInstance;
        QString m_qsAppLocalDataLocation;
        
    };
}